package org.artifact.core.exception;

import org.artifact.core.constant.ConfigConstant;
import org.artifact.core.lang.IServer;

/**
 * @author : DengYing
 * @CreateDate : 2017年7月28日 下午5:44:31
 * @Description ：逻辑异常工具类
 */
public class ArtifactExceptionUtil{

	public static AbstractArtifactException error(final int errorCode) {
		if (IServer.me().getContext().getSetting().getBool(ConfigConstant.isDevMode, true))
			return new ArtifactDevException(errorCode);
		else
			return new ArtifactProException(errorCode);
	}

	public static AbstractArtifactException error(final int errorCode, final String message) {
		if (IServer.me().getContext().getSetting().getBool(ConfigConstant.isDevMode, true))
			return new ArtifactDevException(errorCode, message);
		else
			return new ArtifactProException(errorCode, message);
	}

	public static void isTrue(final int errorCode, final String message, final boolean bool) {
		if (bool) {
			throw error(errorCode, message);
		}
	}

	public static void isTrue(final int errorCode, final boolean bool) {
		if (bool) {
			throw error(errorCode);
		}
	}
}
